package com.firstDay;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Demo10 {
    public static void main(String[] args) {

        ArrayList<Book> bookArrayList = new ArrayList<>();

        Book book = new Book();
        book.setName("kk");
        book.setAuthor("mm");
        book.setPrice(10.0);

        Book book1 = new Book();
        book1.setName("kk");
        book1.setAuthor("hh");
        book1.setPrice(10.0);

        Book book2 = new Book();
        book2.setName("hh");
        book2.setAuthor("ww");
        book2.setPrice(10.0);

        bookArrayList.add(book);
        bookArrayList.add(book1);
        bookArrayList.add(book2);

        Map<String, List<Book>> collect = bookArrayList.stream().collect(Collectors.groupingBy(item -> item.getName()));

        for (Map.Entry<String, List<Book>> stringListEntry : collect.entrySet()) {
            System.out.println("key:" + stringListEntry.getKey());
            System.out.println("value:" + stringListEntry.getValue());
        }

    }
}
